package com.zhuiyun.project.util;
import java.lang.reflect.Field;
import java.util.Objects;
/**
 * @ClassName EntityUtils
 * @Description TODO
 * @Author kdj
 * @Date 2023/8/6 2:22
 **/
public class EntityUtils {
    public static <T> void removeNullFields(T entity) {
        Class<?> clazz = entity.getClass();
        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            try {
                field.setAccessible(true);
                Object value = field.get(entity);

                if (value == null) {
                    // You can either set a default value or just set it to null
                    // field.set(entity, defaultValue);
                    field.set(entity, null);
                }
            } catch (IllegalAccessException e) {
                // Handle the exception if needed
            }
        }
    }
}
